package org.linlinjava.litemall.db.service;

import org.linlinjava.litemall.db.dao.LitemallGoodsSpecificationMapper;
import org.linlinjava.litemall.db.domain.LitemallGoodsSpecification;
import org.linlinjava.litemall.db.domain.LitemallGoodsSpecificationExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

@Service
public class LitemallSpecificationService {

    @Resource
    LitemallGoodsSpecificationMapper specificationMapper;

    public List<LitemallGoodsSpecification> queryByGid(Integer id){
        LitemallGoodsSpecificationExample example = new LitemallGoodsSpecificationExample();
        example.or().andGoodsIdEqualTo(id).andDeletedEqualTo(false);
        return specificationMapper.selectByExample(example);
    }

    public int deleteByGid(Integer id){
        return specificationMapper.updateById(id);
    }

    public int add(LitemallGoodsSpecification specification){
        specification.setAddTime(new Date());
        specification.setUpdateTime(new Date());
        return specificationMapper.insert(specification);
    }

    public int update(LitemallGoodsSpecification specification){
        specification.setAddTime(new Date());
        specification.setUpdateTime(new Date());
        return specificationMapper.updateByPrimaryKeySelective(specification);
    }

}
